<template>
  <div class="showFixedTop">
    <div class="search-container" ref="search">
      <div id="scanCodeSpan" class="left-icon">
        <img src="@/assets/img/icon-scan.png" alt="" />
      </div>
      <form class="search-form">
        <div class="searchBarWrapper">
          <div class="search-form-box" style="background-color: rgb(242, 242, 242);">
            <span class="search-form-icon"></span>
            <div class="search-form-input">
              <router-link to="/search">
                <input type="text" placeholder="搜索商品" readonly="">
              </router-link>
            </div>
          </div>
        </div>
      </form>
      <div class="right-icon" onclick="toMessageNav()">
        <img src="@/assets/img/icon-message.png" alt="" />
        <i></i>
      </div>
    </div>
  </div>
</template>
<script>
export default {
    name: 'searchContainer',
    data () {
        return {
        }
    },
    created(){
        window.addEventListener('scroll', this.handleScroll)
    },
    methods:{
        handleScroll(){
            var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
            if(scrollTop>=100){
                this.$refs.search.style['background']="#fff";
            }
            else{
                this.$refs.search.style['background']="rgba(255, 255, 255, 0.498039)";
            }
        }
    },
    destroyed () {
        window.removeEventListener('scroll', this.handleScroll)
    },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.showFixedTop {
    position: fixed;
    top: 0;
    width: 100%;
    max-width: 750px;
    z-index: 9;
}
.search-container {
    position: relative;
    min-width: 320px;
    max-width: 750px;
    margin: 0 auto;
    z-index: 10;
    width: 100%;
    height: .88rem;
    background-color: rgba(255, 255, 255, 0.498039);
}
.search-container .left-icon {
    display: inline-block;
    height: 100%;
    position: absolute;
    left: .3rem;
    top: .12rem;
    width: .64rem;
    height: .64rem;
    padding-top: .14rem;
    text-align: center;
    background-color: #fff;
    border-radius: 50%;
    overflow: hidden;
}
.search-container .left-icon img {
    display: inline-block;
    width: .4rem;
    height: .36rem;
}
.search-container .search-form {
    display: inline-block;
    height: 100%;
    width: 100%;
    padding: 0 1.4rem;
}
.search-container .search-form .searchBarWrapper {
    padding-top: .12rem;
}
.search-container .search-form .search-form-box {
    position: relative;
    height: .64rem;
    line-height: .64rem;
    background-color: #fff;
    border-radius: 9999px;
    overflow: hidden;
}
.search-container .search-form .search-form-icon {
    background: url('../../../assets/img/icon-search.png') no-repeat;
    position: relative;
    float: left;
    vertical-align: top;
    width: .48rem;
    height: .48rem;
    background-size: contain;
    top: .08rem;
    margin: 0 .15rem 0 .16rem;
}
.search-container .search-form .search-form-input {
    position: absolute;
    left: 0;
    top: 0;
    display: inline-block;
    width: 100%;
    height: 100%;
    padding: 0 .72rem;
}
.search-container .search-form .search-form-input input {
    margin-top: .08rem;
    width: 100%;
    height: .48rem;
    line-height: .48rem;
    font-size: 0.26rem;
    background: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.search-container .right-icon {
    display: inline-block;
    height: 100%;
    position: absolute;
    right: .32rem;
    top: .12rem;
    width: .64rem;
    height: .64rem;
    padding-top: .14rem;
    text-align: center;
    background-color: #fff;
    border-radius: 50%;
}
.search-container .right-icon img {
    display: inline-block;
    width: .4rem;
    height: .36rem;
}
.search-container .right-icon i:empty {
    display: none;
}

.search-container .right-icon i {
    position: absolute;
    top: -0.02rem;
    left: .38rem;
    padding: 0 .1rem;
    display: inline-block;
    height: .28rem;
    line-height: .28rem;
    color: #fff;
    font-size: 0.22rem;
    text-align: center;
    background-color: #FB4545;
    border-radius: 99999px;
}
</style>
